﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Mrc.SqlSurging.DBContext 
{
    public class SugarClientHelper
    {
        public SqlSugarClient GetSqlSugarClient()
        {
            return new SqlSugarClient(ConnectionConfigManager.AppInstance);
        }
    }


    public class DbContext<T> where T : class, new()
    {
        public DbContext()
        {
            Db = new SugarClientHelper().GetSqlSugarClient();
            Db.Aop.OnLogExecuting = (sql,pars) =>
            {
                Console.WriteLine(sql + "\r\n" +
                Db.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value)));
                Console.WriteLine();
            };
        }
        public SqlSugarClient Db;//用来处理事务多表查询和复杂的操作
        
        public SimpleClient<T> CurrentDb { get { return new SimpleClient<T>(Db); } }//用来处理T表的常用操作
    }
}
